


package com.starmark.gateway.pt.provider.web;

import com.starmark.auth.common.util.UserUtil;
import com.starmark.core.framework.base.AbstractController;
import com.starmark.core.framework.response.Response;
import com.starmark.core.framework.response.SuccessResponseData;
import com.starmark.core.framework.util.BeanMapper;
import com.starmark.gateway.pt.provider.service.IPtInterfaceService;
import com.starmark.gateway.pt.provider.vo.PtInterfacePageVo;
import com.starmark.gateway.pt.provider.vo.PtInterfaceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 接口 前端控制器
 * </p>
 *
 * @author starmark
 * @since 2020-05-24
 */
@RestController
@Api(value = "接口管理", description = "接口管理")
@RequestMapping("pt/interface")
public class PtInterfaceController extends AbstractController {
    @Autowired
    IPtInterfaceService ptInterfaceService;

    @ApiOperation(value = "查询接口列表")
    @PostMapping(value = "/query")
    public Object query(@RequestBody Map<String, Object> param) {
        param.put("projectCode", UserUtil.getCurrentUser().getProjectCode());
        return BeanMapper.mapPage(ptInterfaceService.query(param), PtInterfacePageVo.class);
    }


    @ApiOperation(value = "新增或更新接口")
    @PostMapping(value = "/saveOrUpdateInterface")
    public Response saveOrUpdateInterface(@RequestBody PtInterfaceVo ptInterfaceVo) {

        String id = ptInterfaceService.saveOrUpdateInterface(ptInterfaceVo);

        return SuccessResponseData.newInstance(id);
    }

    @ApiOperation(value = "接口详情")
    @GetMapping(value = "/{id}")
    public PtInterfaceVo get(@PathVariable("id") String id) {

        return ptInterfaceService.getPtInterfaceVo(id);
    }


    @DeleteMapping(value = "/{id}")
    @ApiOperation(value = "删除接口")
    public void delete(@PathVariable("id") String id) {

        ptInterfaceService.deleteInterface(id);
    }

}
